<template>
<div>
  <navbar>地址管理</navbar>
  <div style="margin-top: 45px">
    <div>
    <van-address-list
        v-model="chosenAddressId"
        :list="list"
        :disabled-list="disabledList"
        disabled-text="以下地址超出配送范围"
        default-tag-text="默认"
        @add="addAddress"
        @edit="onEdit"

    />
    </div>
  </div>
</div>
</template>

<script>
import {useRouter} from 'vue-router'
import {onMounted,getCurrentInstance,ref,reactive,toRefs} from 'vue'
import NavBar from "@/components/common/navbar";
export default {
  name: "address",
  components: {NavBar},
  setup(){
    let addressList=reactive({
      list:[],
      chosenAddressId:[]
    })
    const {proxy}=getCurrentInstance()
    const router=useRouter()
    const addAddress=()=>{
      router.push({path:'/addressEdit'})
    }
    const onEdit=(val)=>{
      console.log('123',val)
       router.push({path:'/addressEdit',query:{type:'edit',addressId:val.id}})
    }
    onMounted(()=>{
      proxy.$API.address.getAddressList().then(res=>{
        console.log(res)
        addressList.list=res.data.map(item=>{
          return {
            id:item.id,
            name:item.name,
            tel:item.phone,
            address:`${item.province} ${item.city} ${item.county} ${item.address}`,
            isDefault:item.is_default
          }
        })
      })
    })
    return{
      addAddress,
      ...toRefs(addressList),
      onEdit
    }
  }
}
</script>

<style scoped>
/*.btn{*/
/*  margin-top: 20px;*/
/*  margin-left: 40px;*/
/*  width: 300px;*/
/*  background-color:#42b983;*/
/*  border: none;*/
/*  color: white;*/
/*}*/
::v-deep .van-address-list__bottom{
  position: static;
}
::v-deep .van-button{
  border: 1px solid #42b983;
  background-color:#42b983;
}
</style>
